import random

users = {}
num = 0
bank = '中国农业银行的昌平沙河支行'


def c_same(account):
    if users:
        accounts = [x['account'] for x in users.values()]
        return account in accounts
    return False


def create(c_user):
    global num
    if len(users) <= 100:
        if c_same(c_user['account']):
            return 2
        else:
            users[num] = c_user
            num += 1
            return 1
    else:
        return 3
    # print(c_user['account'])
    # res = c_same(c_user['account'])
    # print(res)


def save(account, money):
    if c_same(account):
        for s_user in users.values():
            if s_user['account'] == account:
                print('账号:', s_user['account'], '存之前余额:', s_user['money'])
                s_user['money'] += money
                print('账号:', s_user['account'], '存之后余额:', s_user['money'])
                # print(users)
                break
    else:
        return False


def j_password(account, u_password):
    for j_user in users.values():
        if j_user['account'] == account:
            if j_user['password'] == u_password:
                break
            else:
                return 2


def j_money(account, money):
    for j_user in users.values():
        if j_user['account'] == account:
            if j_user['money'] >= money:
                print('取之前的余额:', j_user['money'])
                j_user['money'] -= money
                print('去之后的余额:', j_user['money'])
                break
            else:
                return 3


def out(account, u_password, money):
    if c_same(account):
        if j_password(account, u_password) != 2:
            if j_money(account, money) != 3:
                return 0
            else:
                return 3
        else:
            return 2
    else:
        return 1


def j_state(j_res):
    if j_res == 0:
        print('正常')
    elif j_res == 1:
        print('账户不存在')
    elif j_res == 2:
        print('密码不对')
    elif j_res == 3:
        print('钱不够')


def c_money(out_account, in_account, out_password, money):
    if c_same(out_account) and c_same(in_account):
        if j_password(out_password, out_password) != 2:
            if j_money(out_account, money) != 3:
                save(in_account, money)
                return 0
            else:
                return 3
        else:
            return 2
    else:
        return 1


def j_card(account, out_money):
    for j_user in users.values():
        if j_user['account'] == account:
            if j_user['type'] == 2 and out_money <= 20000:
                return True
            elif j_user['type'] == 1 and out_money <= 50000:
                return True
            else:
                return False


def print_user(account):
    for p_user in users.values():
        if p_user['account'] == account:
            print('''
            账号：{}
            密码：{}
            余额：{}
      用户居住地址：{}
      账户的开户行：{}
            '''.format(p_user['account'], p_user['password'], p_user['money'], p_user['address'], p_user['bank']))
            break


def find(account, f_password):
    if c_same(account):
        if j_password(account, f_password) != 2:
            print_user(account)
        else:
            print('密码错误')
    else:
        print('该用户不存在')


while 1:
    select = int(input('''
    ***************************
    *   中国农业银行账户管理系统   *
    ***************************
    *           选项           *
    *          1.开户          *
    *          2.存钱          *
    *          3.取钱          *
    *          4.转账          *
    *          5.查询          *
    *          6.Bye          *
    ***************************
    温馨提示：输入选项的数字进行业务选择
    '''))
    if select == 1:
        user = {}
        user['account'] = str(random.randint(10000000, 99999999))
        user['type'] = 2
        user['name'] = input('请输入名字：')
        password = input('请输入6位数字密码：')
        ac = 0
        if len(password) != 6:
            password = input('小zz都说了6位数字,不要多输，重新输入：')
        for c in password:
            if c.isdigit():
                pass
            else:
                ac = 1
                break
        if ac:
            password = input('小zz都说了6位数字还输其他符号,重新输入：')
        user['password'] = password
        user['address'] = input('请输入居住地址：')
        user['money'] = 0
        user['bank'] = bank
        print(user)
        res = create(user)
        if res == 1:
            print('成功')
        elif res == 2:
            print('用户已存在')
        elif res == 3:
            print('用户库已满')
        # print(users)
    elif select == 2:
        u_account = input("请输入账号：")
        s_money = int(input('请输入存入金额:'))
        s_res = save(u_account, s_money)
        if s_res == False:
            print('没有此账户')
    elif select == 3:
        o_account = input('请输入账号：')
        o_password = input('请输入密码：')
        o_money = int(input('请输入取出金额：'))
        res = out(o_account, o_password, o_money)
        j_state(res)
    elif select == 4:
        ou_account = input('请输入转出账号:')
        ou_password = input('请输入转出账号密码:')
        i_account = input('请输入转入账号:')
        money = int(input('请输入转账金额:'))
        c_res = j_card(ou_account, money)
        if c_res:
            res = c_money(ou_account, i_account, ou_password, money)
            j_state(res)
        else:
            print('请在该卡转账额度下进行转账')
    elif select == 5:
        l_account = input('请输入查询账户:')
        l_password = input('请输入查询账户密码:')
        find(l_account, l_password)
    elif select == 6:
        break
# print(type(str(random.randint(10000000, 99999999))))
